{extend name="./common/layout"}

{block name="title"}
Log In
{/block}

{block name="body"}
<script type="text/javascript">
  
</script>
<form id="formAct" action="{$ctx}/index/sw/login" method="post">
      <input id="user1" name="username" type="hidden" required>
      <input id="password1" name="password" type="hidden" required>
</form>
<script type="text/javascript">
  function setCookie(name, value) {
    var Days = 180;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  }

  function getCookie(name) {
      var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
      if (arr = document.cookie.match(reg)) return unescape(arr[2]);
      else return null;
  }

  function delCookie(name) {
      var exp = new Date();
      exp.setTime(exp.getTime() - 1);
      var cval = getCookie(name);
      if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
  }
  function login1() {
    // body...
    document.getElementById('formAct').submit();
  }
  (function() {
    // Your code here...
    //setCookie("user","");
    //setCookie("password","");
    // if(!document.querySelector('.main_logo')) return ;
    // var aEle=document.querySelector('.main_logo').innerHTML='';
    if( "{$status}"!=="E" && getCookie("user")!=null && getCookie('password')!=null){
        document.getElementById('user1').value=getCookie("user");
        document.getElementById('password1').value=getCookie("password");
        login1();
    }
  })();
</script>
<form role="form" action="{$ctx}/index/sw/login" id="form" method="post">
  <fieldset>
    <div class="form-group">
      <input class="form-control" placeholder="账号" id="user" name="username" type="text" required>
    </div>
    <div class="form-group">
      <input class="form-control" placeholder="密码" id="password" name="password" type="password" required>
    </div>
    <center>
      <button  class="btn btn-primary" onclick="subSave()" >保存并登录</button> 
    </center>
  </fieldset>
</form>
<script type="text/javascript">
  (function() {
    // Your code here...
    //setCookie("user","");
    //setCookie("password","");
    // if(!document.querySelector('.main_logo')) return ;
    // var aEle=document.querySelector('.main_logo').innerHTML='';
    if(getCookie("user")!=null && getCookie('password')!=null){
        document.getElementById('user').value=getCookie("user");
        document.getElementById('password').value=getCookie("password");
    }
  })();

  function login() {
    document.getElementById('form').submit();
  }

function subSave(){
    setCookie("user",document.getElementById("user").value);
    setCookie("password",document.getElementById("password").value);
    login();
}


</script>
{/block}